package com.woniuxy.handler;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.thymeleaf.context.WebContext;

import com.woniuxy.pojo.OrderDetail;
import com.woniuxy.pojo.Room;
import com.woniuxy.pojo.RoomType;
import com.woniuxy.service.OrderDetailService;
import com.woniuxy.service.RoomService;
import com.woniuxy.util.DateUtil;
@Controller
@RequestMapping("/")
public class OderDatailHandler {
	//public String date;
	//通过入住和离开日期获取可以住的房间类型
	OrderDetail orderDetail=new OrderDetail();
	DateUtil dateUtil=new DateUtil();
	@Resource
	private OrderDetailService orderDetailService;
	@Resource
	private RoomService roomService;
//	@RequestMapping("/type")
//	@ResponseBody
//	//只做一个调转页面和存值的操作
//	public ModelAndView findRoomType(HttpServletRequest request) throws ParseException{
//		System.out.println("11111111");
//		String date = request.getParameter("date");
//		System.out.println(date);
//		ModelAndView modelAndView=new ModelAndView();
//		modelAndView.addObject("date",date);
//		modelAndView.setViewName("/findroom.html");
//		return modelAndView;
//	}
	//查询可住房间
	@RequestMapping("/types")
	@ResponseBody
	public List<Room> findRoomTypes( String date) throws ParseException{
		System.out.println("22222222");
		Date startdate=new Date();
		Date enddate=new Date();
		ArrayList<java.sql.Date> checkTimes = dateUtil.getCheckTimes(date);
		startdate=checkTimes.get(0);//获取入住日期
		enddate=checkTimes.get(1);//获取预计离开时间
		orderDetail.setCheckin(startdate);
		orderDetail.setCheckout(enddate);
		List<Room> dateByRoom = orderDetailService.dateByRoom(orderDetail);
		return dateByRoom;
		
	}
	//查询可住房间类型
	@RequestMapping("/roomtype")
	@ResponseBody
	public List<RoomType> findRoomType(){
		System.out.println("1111");
		Map<Integer, Integer> findRoomCount = roomService.findRoomCount();
		System.out.println(findRoomCount);
		return null;
		
	}
}
